#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QString>
#include <QFileDialog>
#include <QDebug>
#include <QFile>
#include <QTextStream>
#include <QPlainTextEdit>


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

//    this->setCentralWidget(ui->plainTextEdit);

}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    QString fileName = QFileDialog::getOpenFileName(this,"choose a file",
                "./","ALL(*.*);;Images(*.png *.jpg);;Python文件(*.py)");
    qDebug() << fileName;

    QFile file(fileName);
    if(file.open(QIODevice::ReadOnly|QIODevice::Text))
    {
        QTextStream textStream(&file);
        QString content = textStream.readAll(); // 读取所有的内容
//        while(!textStream.atEnd())
//        {
//            content.append(textStream.readLine());
//        }
        ui->plainTextEdit->setPlainText(content);
    }
}
